import http from '@/http';
import { SubmissionDetail, StatusOption, SubmissionListParams } from '@/types/submission';
import { PaginatedResponse } from '@/types/common';

interface SubmitRequest {
  problem: number;
  language: string;
  code: string;
  contest_id?: number | null;
  shared?: boolean;
}

interface SubmitResponse {
  id: string;
  problem: number;
  contest: number | null;
  code: string;
  language: string;
  result: number;
  create_time: string;
  shared: boolean;
  info: any;
  statistic_info: any;
}

interface DebugRequest {
  problem_id: number;
  language: string;
  code: string;
  test_case: Array<{input: string, output: string}>;
  contest_id?: number | null;
}

interface DebugResponse {
  debug_id: string;
}

interface DebugResult {
  result: number;
  info: any;
  statistic_info: any;
}

export const submissionService = {
  submit(data: SubmitRequest) {
    return http.post<SubmitResponse>('/api/submission/', data);
  },

  getSubmissions(params: SubmissionListParams) {
    return http.get<PaginatedResponse<SubmissionDetail>>('api/submission/', { params });
  },

  getSubmissionDetail(id: string) {
    return http.get<SubmissionDetail>(`api/submission/${id}/`);
  },

  getStatusList() {
    return http.get<StatusOption[]>('api/submission/get_status_list/');
  },

  rejudge(id: string) {
    return http.get(`/api/submission/${id}/re_judge/`);
  },
  
  // 提交调试请求
  debug(data: DebugRequest) {
    return http.post<DebugResponse>('/api/debug/', data);
  },
  
  // 获取调试结果
  getDebugResult(debugId: string) {
    return http.get<DebugResult>(`/api/debug/?debug_id=${debugId}`);
  },
}; 